﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tesla.Service.DataContracts;
using Tesla.DataAccess.DataAccessComponents;
using Tesla.Util.Utilities;
using Tesla.DataAccess.DataAccessLogic.Interfaces;

namespace Tesla.DataAccess.DataAccessLogic.Implementations
{
    public class TimeSheetDA : BaseOperationalDA,ITimeSheetDA
    {
        public IList<BaseDC> ReadTasksForTimeSheet(int ProjectID, int FinYrID, int EmpID)
        {
            try
            {
                using (TeslaDataContext context = new TeslaDataContext())
                {
                    context.DeferredLoadingEnabled = false;
                    IEnumerable<usp_ReadProjectPlanResult> taskList = context.usp_ReadProjectPlan(ProjectID, FinYrID, EmpID).Cast<usp_ReadProjectPlanResult>();
                    return GenericConversion.ConvertToTargetType(taskList.ToList<usp_ReadProjectPlanResult>().ToArray(), typeof(usp_ReadProjectPlanResult), typeof(TimeSheetDC));

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public IList<BaseDC> ReadWeeksCalendar(int ProjectID, int FinYr, DateTime refdate)
        {
            try
            {
                using (TeslaDataContext context = new TeslaDataContext())
                {
                    context.DeferredLoadingEnabled = false;
                    IEnumerable<usp_ReadWeekDaysResult> days = context.usp_ReadWeekDays(ProjectID, FinYr, refdate).Cast<usp_ReadWeekDaysResult>();
                    return GenericConversion.ConvertToTargetType(days.ToList<usp_ReadWeekDaysResult>().ToArray(), typeof(usp_ReadWeekDaysResult), typeof(TimesheetDaysDC));

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

